package com.jpcc.vw.onlineRadio.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.os.RemoteException;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.cns.android.atmospherelamp.AtmosphereLampManager;
import com.jpcc.vw.onlineRadio.R;
import com.jpcc.vw.onlineRadio.application.MusicApplication;
import com.jpcc.vw.onlineRadio.constants.Constants;
import com.jpcc.vw.onlineRadio.model.IRadio;
import com.jpcc.vw.onlineRadio.model.bean.BaseBean;
import com.jpcc.vw.onlineRadio.model.bean.VIPInfoBean;
import com.jpcc.vw.onlineRadio.model.impl.RadioImpl;
import com.jpcc.vw.onlineRadio.utils.CommonSubscriber;
import com.jpcc.vw.onlineRadio.utils.ProcessInfoUtils;
import com.jpcc.vw.onlineRadio.utils.ToastUtils;
import com.orhanobut.logger.Logger;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class BaseDiscoverActivity extends com.jpcc.vw.onlineRadio.base.BaseActivity {

    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.imv_top_bottom_line)
    ImageView imv_top_bottom_line;
    private IRadio radioModel;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_discover;
    }

    @Override
    public void setupView() {
        ButterKnife.bind(this);
        tv_title.setText(getResources().getString(R.string.string_1));
        radioModel=new RadioImpl();
        getVipInfo();
    }

    public void getVipInfo() {
        radioModel.QueryVIPInfo().subscribe(new CommonSubscriber<VIPInfoBean>() {
            @Override
            public void onSuccess(VIPInfoBean response) {

            }

            @Override
            public void onFailure(BaseBean response) {

            }
        });
    }

    @Override
    public void setStatusBar() {
        this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); //隐藏状态栏
    }

    @Override
    public void setupData() {
        if (Constants.isRelease) {
            try {
                boolean atmosphereStatus = AtmosphereLampManager.getInstance(this).isHmiAtmosphereLampOn();
                String color = AtmosphereLampManager.getInstance(this).getHmiAtmosphereLampColor();
                doAtmosphere(atmosphereStatus, color);
            } catch (RemoteException e) {
                e.printStackTrace();
            }



            ConnectivityManager connectivityManager = (ConnectivityManager) MusicApplication.GetInstance().getSystemService(Context.CONNECTIVITY_SERVICE);
            boolean connected = connectivityManager.getNetworkStatus();
            Logger.i("playhistory network status-->"+connected);
            if (!connected) {
//                if (ProcessInfoUtils.isForeground(MusicApplication.GetInstance())) {
//                    ToastUtils.show(getResources().getString(R.string.string_87));
//                }
            }





        }
    }

    @Override
    public void doAtmosphere(boolean rgbOn, String color) {
        Logger.i("doAtmosphere" + "rgbOn-->" + rgbOn);
        Logger.i("doAtmosphere" + "color-->" + color);
        if (rgbOn) {
            if (TextUtils.isEmpty(color)) {
                imv_top_bottom_line.setColorFilter(Color.TRANSPARENT);
            } else {
                imv_top_bottom_line.setColorFilter(Color.parseColor(color));
            }
        } else {
            imv_top_bottom_line.setColorFilter(Color.TRANSPARENT);
        }
    }





    @OnClick({R.id.layout_online_radio, R.id.layout_online_program,R.id.layout_back,R.id.imv_new_search})
    void doClicks(View view) {
        int id = view.getId();
        switch (id) {
            case R.id.layout_online_radio:
                Intent intent_online_radio = new Intent(this, OnlineRadioActivity.class);
                startActivity(intent_online_radio);
                break;
            case R.id.layout_online_program:
                Intent intent = new Intent(this, DiscoverActivity.class);
                startActivity(intent);
                break;
            case R.id.layout_back:
                this.finish();
                break;
            case R.id.imv_new_search:
                Intent intent1=new Intent(this,SearchActivity.class);
                startActivity(intent1);
                break;
        }
    }
}
